﻿using System.Collections.Generic;
using System.Linq;
using Silent.MDB.Common.Services;

namespace Silent.MDB.Server.Model.Services
{
    public class RepositoryServiceBase<T> : IRepositoryService<T>
    {
        public void Add(T item, string location)
        {
            ApplicationCore.RepositoryManagers[location]
                .GetRepository<T>()
                .Add(item);
        }

        public void Update(T item, string location)
        {
            ApplicationCore.RepositoryManagers[location]
                .GetRepository<T>()
                .Update(item);
        }

        public void Remove(T item, string location)
        {
            ApplicationCore.RepositoryManagers[location]
                .GetRepository<T>()
                .Remove(item);
        }

        public ICollection<T> Load(T filter, string location)
        {
            return ApplicationCore.RepositoryManagers[location]
                        .GetRepository<T>()
                        .Load(filter)
                        .ToList();
        }

        public void Save(ICollection<T> data, string location)
        {
            ApplicationCore.RepositoryManagers[location]
                .GetRepository<T>()
                .Save(data);
        }
    }
}
